﻿using FreeRedis;
using Microsoft.Extensions.DependencyInjection;

namespace ED.FreeRedis
{
    /// <summary>
    /// FreeRedis帮助类
    /// </summary>
    public static class FreeRedisHelp
    {
        public static IServiceCollection AddFreeRedis(this IServiceCollection service, Action<RedisConfig> setupOptions)
        {
            RedisConfig redisConfig = new RedisConfig();
            setupOptions?.Invoke(redisConfig);
            RedisClient cli = new RedisClient(redisConfig.RedisUrl);
            cli.Notice += (s, e) => Console.WriteLine(e.Log); //打印命令日志
            service.AddSingleton<IRedisClient>(cli);
            return service;
        }
    }
}